package interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import util.MyConfig;

public class LoginInterceptor extends HandlerInterceptorAdapter {
	@Resource
	private MyConfig myConfig;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// System.out.println("判断用户是否登录" + request.getRequestURI());
		Boolean flag = true;
		String userId = (String) request.getSession().getAttribute(request.getSession().getId());
		if (userId == null) {
			response.sendRedirect(myConfig.getLoginPage());
			flag = false;
		}
		return flag;
	}

}
